//
// Created by 1 on 2020-10-26.
//

#ifndef CTY_STACKMIN_H
#define CTY_STACKMIN_H
class StackMin {
public:
    int cache[20001];
    int v_min = 0;
    int v_index = 0;
    /** initialize your data structure here. */
    StackMin() {

    }

    void push(int x) {
        if (x < v_min ){
            v_min = x;
        }
        cache[v_index] = x;
        ++ v_index;
    }

    void pop() {
        -- v_index;
        v_min = cache[v_index];
        for(int i = 0; i < v_index ; i ++){
            if(cache[i] < v_min){
                v_min = cache[i];
            }
        }
    }

    int top() {
        return cache[v_index - 1];
    }

    int min() {
        return v_min;
    }
};
#endif //CTY_STACKMIN_H
